import React, {Component, Suspense} from 'react';
import LoadingPortal from "component/portal/LoadingPortal";
import {Route, RouteComponentProps, Switch} from "react-router";
import {routes} from "router/routes/app";
import {withRouter} from "react-router-dom";
import {IRouteProps} from "interface/app";

export interface IAppRouterProps extends RouteComponentProps {
}

export interface IAppRouterState {
    routeList:IRouteProps[]
}


class AppRouter extends Component<IAppRouterProps,IAppRouterState> {

    state={
        routeList: routes,
    }

    render() {
        return (
            <Suspense fallback={<LoadingPortal />}>

                <Switch>
                    {this.state.routeList.map(item => <Route {...item}></Route>)}
                </Switch>
            </Suspense>
        );
    }
}

export default withRouter(AppRouter);
